home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / nx_arc / arc.c next >
Encoding:
C/C++ Source or Header  |  1992-12-20  |  10.1 KB  |  327 lines

  1. /*
  2.  * $Log:    arc.c,v $
  3.  * Revision 1.4  88/04/11  19:03:58  hyc
  4.  * another omitted section. Ooops.
  5.  * 
  6.  * Revision 1.3  88/04/11  19:01:11  hyc
  7.  * added printf accidentally omitted...
  8.  * 
  9.  * Revision 1.2  88/04/11  17:35:34  hyc
  10.  * re-synch with MTS version, add squashing support.
  11.  * 
  12.  * Revision 1.1  88/04/11  17:24:19  hyc
  13.  * Initial revision
  14.  * 
  15.  * Revision 1.4  87/12/20  03:39:46  hyc
  16.  * Fix command description (MTS vs Unix usage of 'i' flag...)
  17.  * 
  18.  * Revision 1.3  87/12/19  04:35:12  hyc
  19.  * Change MTS to MSDOS for #ifdef of printf for image mode...
  20.  * 
  21.  * Revision 1.2  87/12/19  04:00:18  hyc
  22.  * MAde #ifdef of image #ifndef MSDOS...
  23.  * 
  24.  * Revision 1.1  87/12/19  03:59:14  hyc
  25.  * Initial revision
  26.  * 
  27.  * Revision 1.5  87/08/13  17:02:39  hyc
  28.  * Run thru the indent program...
  29.  *  Revision 1.4  87/07/30  03:38:15  hyc Minor junk
  30.  * 
  31.  * Revision 1.3  87/07/21  11:39:35  hyc minor fixups
  32.  * 
  33.  * Revision 1.2  87/07/21  06:23:13  hyc Modified according to the mods made to
  34.  * arc 5.12 for unix.
  35.  * 
  36.  */
  37.  
  38. /*
  39.  * ARC - Archive utility
  40.  * 
  41.  * Version 5.20, created on 10/24/86 at 14:56:41
  42.  * 
  43.  * (C) COPYRIGHT 1985,86 by System Enhancement Associates; ALL RIGHTS RESERVED
  44.  * 
  45.  * By:  Thom Henderson
  46.  * 
  47.  * Description: This program is a general archive utility, and is used to
  48.  * maintain an archive of files.  An "archive" is a single file that combines
  49.  * many files, reducing storage space and allowing multiple files to be
  50.  * handled as one.
  51.  * 
  52.  * Instructions: Run this program with no arguments for complete instructions.
  53.  * 
  54.  * Programming notes: ARC Version 2 differs from version 1 in that archive
  55.  * entries are automatically compressed when they are added to the archive,
  56.  * making a separate compression step unecessary.  The nature of the
  57.  * compression is indicated by the header version number placed in each
  58.  * archive entry, as follows:
  59.  * 
  60.  *    1 = Old style, no compression
  61.  *    2 = New style, no compression
  62.  *    3 = Compression of repeated characters only
  63.  *    4 = Compression of repeated characters plus Huffman SQueezing
  64.  *    5 = Lempel-Zev packing of repeated strings (old style)
  65.  *    6 = Lempel-Zev packing of repeated strings (new style)
  66.  *    7 = Lempel-Zev Williams packing with improved hash function
  67.  *    8 = Dynamic Lempel-Zev packing with adaptive reset
  68.  *    9 = Squashing, ala Phil Katz's PKARC
  69.  * 
  70.  * Type 5, Lempel-Zev packing, was added as of version 4.0
  71.  * 
  72.  * Type 6 is Lempel-Zev packing where runs of repeated characters have been
  73.  * collapsed, and was added as of version 4.1
  74.  * 
  75.  * Type 7 is a variation of Lempel-Zev using a different hash function which
  76.  * yields speed improvements of 20-25%, and was added as of version 4.6
  77.  * 
  78.  * Type 8 is a different implementation of Lempel-Zev, using a variable code
  79.  * size and an adaptive block reset, and was added as of version 5.0
  80.  *
  81.  * Type 9 is yet another implementation of Lempel-Zev, used originally by
  82.  * Phil Katz in his PKARC utility.
  83.  * 
  84.  * Verion 4.3 introduced a temporary file for holding the result of the first
  85.  * crunch pass, thus speeding up crunching.
  86.  * 
  87.  * Version 4.4 introduced the ARCTEMP environment string, so that the temporary
  88.  * crunch file may be placed on a ramdisk.  Also added was the distinction
  89.  * bewteen Adding a file in all cases, and Updating a file only if the disk
  90.  * file is newer than the corresponding archive entry.
  91.  * 
  92.  * The compression method to use is determined when the file is added, based on
  93.  * whichever method yields the smallest result.
  94.  * 
  95.  * Language: Computer Innovations Optimizing C86
  96.  */
  97. #include <stdio.h>
  98. #include "arc.h"
  99.  
  100. main(num, arg)            /* system entry point */
  101.     INT             num;    /* number of arguments */
  102.     char           *arg[];    /* pointers to arguments */
  103. {
  104.     char            opt = 0;/* selected action */
  105.     char           *a;    /* option pointer */
  106.     char           *makefnam();    /* filename fixup routine */
  107.     char           *upper();/* case conversion routine */
  108.     char           *index();/* string index utility */
  109.     char           *envfind();    /* environment searcher */
  110.     INT             n;    /* argument index */
  111.     char           *arctemp2, *malloc();
  112. #ifdef BSD
  113.     LONG            getpid();
  114. #endif
  115. #ifdef MTS
  116.     fortran         guinfo();
  117.     char            gotinf[4];
  118. #endif
  119.  
  120.     if (num < 3) {
  121.         printf("ARC - Archive utility, Version 5.20, created on 10/24/86 at 14:56:41\n");
  122.         /*
  123.          * printf("(C) COPYRIGHT 1985,86 by System Enhancement
  124.          * Associates;"); printf(" ALL RIGHTS RESERVED\n\n");
  125.          * printf("Please refer all inquiries to:\n\n"); printf("
  126.          * System Enhancement Associates\n"); printf("       21 New
  127.          * Street, Wayne NJ 07470\n\n"); printf("You may copy and
  128.          * distribute this program freely,"); printf(" provided
  129.          * that:\n"); printf("    1)   No fee is charged for such
  130.          * copying and"); printf(" distribution, and\n"); printf(" 2) 
  131.          * It is distributed ONLY in its original,"); printf("
  132.          * unmodified state.\n\n"); printf("If you like this program,
  133.          * and find it of use, then your"); printf(" contribution
  134.          * will\n"); printf("be appreciated.  You may not use this
  135.          * product in a"); printf(" commercial environment\n");
  136.          * printf("or a governmental organization without paying a
  137.          * license"); printf(" fee of $35.  Site\n");
  138.          * printf("licenses and commercial distribution licenses
  139.          * are"); printf(" available.  A program\n"); printf("disk
  140.          * and printed documentation are available for $50.\n");
  141.          * printf("\nIf you fail to abide by the terms of this
  142.          * license, "); printf(" then your conscience\n");
  143.          * printf("will haunt you for the rest of your life.\n\n"); 
  144.          */
  145. #ifdef MSDOS
  146.         printf("Usage: ARC {amufdxerplvtc}[bswnoq][g<password>]");
  147. #endif
  148. #ifdef BSD
  149.         printf("Usage: arc {amufdxerplvtc}[biswnoq][g<password>]");
  150. #endif
  151. #ifdef MTS
  152.         printf("Parameters: {amufdxeplvtc}[biswnoq][g<password>]");
  153. #endif
  154.         printf(" <archive> [<filename> . . .]\n");
  155.         printf("Where:   a   = add files to archive\n");
  156.         printf("         m   = move files to archive\n");
  157.         printf("         u   = update files in archive\n");
  158.         printf("         f   = freshen files in archive\n");
  159.         printf("         d   = delete files from archive\n");
  160.         printf("         x,e = extract files from archive\n");
  161. #ifndef MTS
  162.         printf("         r   = run files from archive\n");
  163. #endif
  164.         printf("         p   = copy files from archive to");
  165.         printf(" standard output\n");
  166.         printf("         l   = list files in archive\n");
  167.         printf("         v   = verbose listing of files in archive\n");
  168.         printf("         t   = test archive integrity\n");
  169.         printf("         c   = convert entry to new packing method\n");
  170.         printf("         b   = retain backup copy of archive\n");
  171. #ifdef    MTS
  172.         printf("         i   = suppress ASCII/EBCDIC translation\n");
  173. #endif
  174. #ifdef    BSD
  175.         printf("         i   = suppress CRLF to '\\n' translation\n");
  176. #endif
  177.         printf("         s   = suppress compression (store only)\n");
  178.         printf("         w   = suppress warning messages\n");
  179.         printf("         n   = suppress notes and comments\n");
  180.         printf("         o   = overwrite existing files when");
  181.         printf(" extracting\n");
  182.         printf("         q   = squash instead of crunching\n");
  183.         printf("         g   = Encrypt/decrypt archive entry\n");
  184.     /*    printf("\nPlease refer to the program documentation for");
  185.         printf(" complete instructions.\n"); */
  186.         return 1;
  187.     }
  188.     /* see where temp files go */
  189.     /* use process id to insure unique temp files */
  190.  
  191. #ifndef MTS
  192.     arctemp = malloc(256);
  193.     if (!(arctemp2 = envfind("ARCTEMP")))
  194.         arctemp2 = envfind("TEMP");
  195.     if (arctemp2)
  196.         sprintf(arctemp, "%s.Arc%ld", arctemp2, getpid());
  197.     else
  198.         sprintf(arctemp, ".Arc%ld", getpid());
  199. #else
  200.     guinfo("SHFSEP  ", gotinf);
  201.     sepchr[0] = gotinf[0];
  202.     guinfo("SCRFCHAR", gotinf);
  203.     tmpchr[0] = gotinf[0];
  204.     arctemp = "-$$$";
  205.     arctemp[0] = tmpchr[0];
  206. #endif
  207.  
  208. #ifndef BSD
  209.     /* avoid any case problems with arguments */
  210.  
  211.     for (n = 1; n < num; n++)    /* for each argument */
  212.         upper(arg[n]);    /* convert it to uppercase */
  213. #else
  214.     /* avoid case problems with command options */
  215.     upper(arg[1]);        /* convert to uppercase */
  216. #endif
  217.  
  218.     /* create archive names, supplying defaults */
  219. #ifndef BSD
  220.     makefnam(arg[2], ".ARC", arcname);
  221. #else
  222.     makefnam(arg[2], ".arc", arcname);
  223. #endif
  224.     /* makefnam(".$$$",arcname,newname); */
  225.     sprintf(newname, "%s.ARC", arctemp);
  226.     makefnam(".BAK", arcname, bakname);
  227.  
  228.     /* now scan the command and see what we are to do */
  229.  
  230.     for (a = arg[1]; *a; a++) {    /* scan the option flags */
  231. #ifndef MTS
  232.         if (index("AMUFDXEPLVTCR", *a)) {    /* if a known command */
  233. #else
  234.         if (index("AMUFDXEPLVTC", *a)) {
  235. #endif
  236.             if (opt)/* do we have one yet? */
  237.                 arc_abort("Cannot mix %c and %c", opt, *a);
  238.             opt = *a;    /* else remember it */
  239.         } else if (*a == 'B')    /* retain backup copy */
  240.             keepbak = 1;
  241.  
  242.         else if (*a == 'W')    /* suppress warnings */
  243.             warn = 0;
  244. #ifndef MSDOS
  245.         else if (*a == 'I')    /* image mode, no ASCII/EBCDIC x-late */
  246.             image = 1;
  247. #endif
  248.  
  249.         else if (*a == 'N')    /* suppress notes and comments */
  250.             note = 0;
  251.  
  252.         else if (*a == 'O')    /* overwrite file on extract */
  253.             overlay = 1;
  254.  
  255.         else if (*a == 'G') {    /* garble */
  256.             password = a + 1;
  257.             while (*a)
  258.                 a++;
  259.             a--;
  260. #ifdef MTS
  261.             etoa(password, strlen(password));
  262. #endif
  263.         } else if (*a == 'S')    /* storage kludge */
  264.             nocomp = 1;
  265.  
  266.         else if (*a == 'K')    /* special kludge */
  267.             kludge = 1;
  268.  
  269.         else if (*a == 'Q')    /* use squashing */
  270.             dosquash = 1;
  271.  
  272.         else if (*a == '-' || *a == '/')    /* UNIX and PC-DOS
  273.                              * option markers */
  274.             ;
  275.  
  276.         else
  277.             arc_abort("%c is an unknown command", *a);
  278.     }
  279.  
  280.     if (!opt)
  281.         arc_abort("I have nothing to do!");
  282.  
  283.     /* act on whatever action command was given */
  284.  
  285.     switch (opt) {        /* action depends on command */
  286.     case 'A':        /* Add */
  287.     case 'M':        /* Move */
  288.     case 'U':        /* Update */
  289.     case 'F':        /* Freshen */
  290.         addarc(num - 3, &arg[3], (opt == 'M'), (opt == 'U'), (opt == 'F'));
  291.         break;
  292.  
  293.     case 'D':        /* Delete */
  294.         delarc(num - 3, &arg[3]);
  295.         break;
  296.  
  297.     case 'E':        /* Extract */
  298.     case 'X':        /* eXtract */
  299.     case 'P':        /* Print */
  300.         extarc(num - 3, &arg[3], (opt == 'P'));
  301.         break;
  302.  
  303.     case 'V':        /* Verbose list */
  304.         bose = 1;
  305.     case 'L':        /* List */
  306.         lstarc(num - 3, &arg[3]);
  307.         break;
  308.  
  309.     case 'T':        /* Test */
  310.         tstarc();
  311.         break;
  312.  
  313.     case 'C':        /* Convert */
  314.         cvtarc(num - 3, &arg[3]);
  315.         break;
  316. #ifndef MTS
  317.     case 'R':        /* Run */
  318.         runarc(num - 3, &arg[3]);
  319.         break;
  320. #endif
  321.     default:
  322.         arc_abort("I don't know how to do %c yet!", opt);
  323.     }
  324.  
  325.     return nerrs;
  326. }
  327.